package com.superteam.zzl.adapter.RecommendFragmentAdapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.superteam.zzl.activity.R;
import com.superteam.zzl.model.RecommendFragment.MainData;

import java.util.ArrayList;

/**
 * Created by zhang on 2017/1/9.
 */

/**
 * 推荐页面 人气推荐适配器
 */

public class LvRecAdapter extends BaseAdapter {

    private Context context;
    private ArrayList<MainData.ItemsBean.ItemListBean> list;

    public LvRecAdapter(Context context,ArrayList<MainData.ItemsBean.ItemListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.recommendfragment_item_lv_rec,null);
            vh = new ViewHolder();
            vh.iv = (ImageView)convertView.findViewById(R.id.iv_lv_rec);
            vh.tv_title = (TextView)convertView.findViewById(R.id.tv_title_lv_rec);
            vh.tv_price = (TextView)convertView.findViewById(R.id.tv_price_lv_rec);
            vh.tv_count = (TextView)convertView.findViewById(R.id.tv_count_lv_rec);
            vh.tv_good = (TextView)convertView.findViewById(R.id.tv_good_lv_rec);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv_title.setText(list.get(position).getTitle());
        vh.tv_price.setText("¥"+list.get(position).getLprice()+"元起");
        vh.tv_count.setText("已售 " + list.get(position).getSaleCount()+" 份");
        vh.tv_good.setText(list.get(position).getEvaluateCount()+"评价");
        //Log.e("data",list.get(position).getUrl());
        Glide.with(context).load(list.get(position).getMainImage()).into(vh.iv);
        return convertView;
    }

    class ViewHolder{
        ImageView iv;
        TextView tv_title,tv_price,tv_count,tv_good;
    }
}
